//
//  MessageView.m
//  JST
//
//  Created by Mac on 15/8/25.
//  Copyright (c) 2015年 aniuge. All rights reserved.
//

#import "MessageView.h"

#import "FaceView.h"

@interface MessageView ()<UIScrollViewDelegate,FaceViewDelegate>

//分割线
@property (nonatomic, strong) UIView *sepView;

@property (nonatomic,strong)UIPageControl *pageControl;
@end
#define FaceSectionBarHeight  36   // 表情下面控件
#define FacePageControlHeight 30  // 表情pagecontrol

#define Pages 3
@implementation MessageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUp];
    }
    return self;
}

-(void)setUp
{
    self.backgroundColor = kANGBackgoundColor;
    
    //分割线
    _sepView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kDeviceWidth, 0.5)];
    _sepView.backgroundColor = [UIColor colorWithHexString:@"9fa0a0"];
    [self addSubview:_sepView];
    
    UIScrollView *scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, CGRectGetWidth(self.bounds),CGRectGetHeight(self.bounds)-FacePageControlHeight-FaceSectionBarHeight)];
    scrollView.pagingEnabled=YES;
    scrollView.showsHorizontalScrollIndicator=NO;
    //设置大小
    scrollView.contentSize=CGSizeMake(Pages*kDeviceWidth, 0);
    
    //设置代理
    scrollView.delegate=self;
   
    [self addSubview:scrollView];
    for (int i=0; i<Pages; i++) {
        FaceView *faceView=[[FaceView alloc] initWithFrame:CGRectMake(i*kDeviceWidth, 0, kDeviceWidth, CGRectGetHeight(scrollView.frame)) forIndexPath:i];
        
        faceView.delegate=self;
        
        [scrollView addSubview:faceView];
        
    }
    
    _pageControl = [[UIPageControl alloc]init];
    [_pageControl setFrame:CGRectMake(0,CGRectGetMaxY(scrollView.frame),CGRectGetWidth(self.bounds),FacePageControlHeight)];
    [self addSubview:_pageControl];
    [_pageControl setPageIndicatorTintColor:[UIColor lightGrayColor]];
    [_pageControl setCurrentPageIndicatorTintColor:[UIColor grayColor]];
    _pageControl.numberOfPages = Pages;
    _pageControl.currentPage   = 0;
    
}
#pragma mark =============代理方法===================
#pragma mark scrollViewDelegate
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    _pageControl.currentPage=(int)scrollView.contentOffset.x/kDeviceWidth;
   
}
#pragma mark FaceViewDelegate
-(void)faceViewWithFaceButtonClick:(UIButton *)but
{
    if (_delegate&&[_delegate respondsToSelector:@selector(messageViewFaceWithButton:)])
    {
        [_delegate messageViewFaceWithButton:but];
    }
}

@end
